<?php

namespace app\admin\controller;

use think\Db;
use think\response\Json;

Class Work extends Base
{
    public function edit(){
        $id = $this->request->param('id');
        $row = Db::table("tb_work")->where("id",$id)->find();
        if ($row){
            $imgs = [];
            if ($row['imgs']){
                $imgs = explode(',',$row['imgs']);
            }
            $row['imgs'] = $imgs;
        }
        if ($this->request->isPost()) {
            $data = $this->request->post();
            if (empty($data["answer"])){
                return ['status' => 'n', 'info' => '输入回复内容'];
            }
            $sqldata = array();
            $sqldata["answer"]=$data["answer"];
            $sqldata["status"]=1;
            $sqldata["rtime"]=time();
            $res = Db::table("tb_work")->where("id",$id)->update($sqldata);
            if ($res) {
                return ['status' => 'y', 'info' => '操作成功'];
            } else {
                return ['status' => 'n', 'info' => '操作失败'];
            }
        }
        return view('', ['row' => $row]);
    }

    public function list(){
        $param = $this->request->get();
        $obj=Db::table("tb_work");
        if (isset($param['word']) && $param['word']) {
            $obj->where('uid', $param['word']);
        }
        if (isset($param['status']) && $param['status']>-1) {
            $obj->where('status', $param['status']);
        }
        if (isset($param['start']) && $param['start']) {
            $obj->where('time', '>', $param['start'] . " 00:00:00");
        }
        if (isset($param['end']) && $param['end']) {
            $obj->where('time', '<', $param['end'] . " 00:00:00");
        }
        $list = $obj->paginate(10, false, ['query' => $this->request->param()]);

        return view('', ['list' => $list]);
    }

}